package br.ds.twitter4a;

import org.apache.http.Header;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;
import br.ds.twitter4a.rest.TwitterTokenRequest;

import com.loopj.android.http.AsyncHttpResponseHandler;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	new Handler().postDelayed(new Runnable() {

	    @Override
	    public void run() {
		// TODO Auto-generated method stub
		requestToken();

	    }
	}, 1000);
    }

    private void requestToken() {
	new TwitterTokenRequest().execute(new AsyncHttpResponseHandler() {
	    /** {@inheritDoc} */
	    @Override
	    public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
		Toast.makeText(getApplicationContext(), "funfou",
			Toast.LENGTH_LONG).show();
		super.onSuccess(arg0, arg1, arg2);
	    }

	    /** {@inheritDoc} */
	    @Override
	    public void onFailure(int arg0, Header[] arg1, byte[] arg2,
		    Throwable arg3) {
		Toast.makeText(
			getApplicationContext(),
			"bugou: " + arg3.getMessage() + " "
				+ arg1[0].toString(), Toast.LENGTH_LONG).show();
		super.onFailure(arg0, arg1, arg2, arg3);
	    }
	});
    }
}
